package com.zzz.friend.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @BelongsProject: oj-project
 * @BelongsPackage: com.zzz.conmmon.core.utils
 * @Author: zhai
 * @CreateTime: 2025-09-22  09:08
 * @Description: TODO BCrypt加密算法
 * @Version: 1.0
 */
public class BCryptUtils {

    /**
     * @description: ⽣成加密后密⽂
     * @author: zhai
     * @date: 2025/9/22 09:09
     * @param:
     * @return: 加密字符串
     **/
    public static String encryptPassword(String password) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        return bCryptPasswordEncoder.encode(password);
    }

    /**
     * @description: 验证密码是否匹配
     * @author: zhai
     * @date: 2025/9/22 09:33
     * @param: [rawPassword, encodedPassword]
     * @return: boolean
     **/
    public static boolean matchesPassword(String rawPassword, String encodedPassword) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword, encodedPassword);
    }

    public static void main(String[] args) {
        System.out.println(encryptPassword("123456"));
    }
}
